package com.zdc.learn.netty.heart;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandler;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.timeout.IdleStateEvent;

import javax.security.sasl.SaslServer;

//服务端 处理 handler
public class HeartServerChatHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        if (evt instanceof IdleStateEvent){
            IdleStateEvent id = (IdleStateEvent) evt;
            switch (id.state()){
                case READER_IDLE:
                    System.out.println("读空闲");
                    break;
                case WRITER_IDLE:
                    System.out.println("写空闲");
                    break;
                case ALL_IDLE:
                    System.out.println("读写空闲");
                    break;
            }
            System.out.println(ctx.channel().remoteAddress() + "--超时时间--" + id.state());
            System.out.println("服务器做相应处理..");
            ctx.channel().close();
            ctx.channel().closeFuture();
        }
    }
}
